package dm_pm;

/**
 * A class to describe one of many instances of a periodic task.
 * 
 * @author Tom Deering
 * @author Dossay Oryspayev
 * 
 */
public class Instance {
	/**The absolute tick time deadline for this task instance*/
	private long deadline;
	/**The amount of computation time this instance has left to execute*/
	private long computation;
	/**The amount of computation time the set of shared task instances have left to execute*/
	private long sharedComputationLeft;
	/**The identifier of the task that generated this instance*/
	private long taskID;
	

	/** This variable is used for all instances. */
	private boolean shared;
	/** This variable is only used for shared instances. Since,
	 * shared instance cannot decrement its computation time immediately if it is
	 * not the first job.
	 * */
	private long startTime;
	
	/** This is needed for computation of maximum interference, otherwise
	 * we'll have to look up the period from the task set using taskID
	 * which will take quite a time.
	 * */
	private long period;
	
	/**
	 * We need priority while sorting because we cannot sort shared instances
	 * based on deadline info, whereas to sort the non shared instances based
	 * on deadline value would be fine.
	 * 
	 * For non shared instances we will have this value set to the deadline.
	 */
	private long priority;
	
	
	/**
	 * Generates a new instance with given properties
	 * @param taskID
	 * @param absDeadline
	 * @param computation
	 * @param sharedComputation
	 */
	public Instance(long computation, long deadline, long taskID, long startTime){
		this.computation = computation;
		this.deadline = deadline;
		this.taskID = taskID;
		this.startTime = startTime;
		//this.sharedComputationLeft = sharedComputation;
	}


	public long getDeadline() {
		return deadline;
	}

	public void setDeadline(long deadline) {
		this.deadline = deadline;
	}

	public long getComputation() {
		return computation;
	}

	public void setComputation(long computation) {
		this.computation = computation;
	}


	public boolean isShared() {
		return shared;
	}

	public void setShared(boolean shared) {
		this.shared = shared;
	}
	
	
	public long getStartTime() {
		return startTime;
	}


	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}	

	
	public long getTaskID() {
		return taskID;
	}


	public void setTaskID(long taskID) {
		this.taskID = taskID;
	}

	public long getPeriod() {
		return period;
	}


	public void setPeriod(long period) {
		this.period = period;
	}



	public long getPriority() {
		return priority;
	}


	public void setPriority(long priority) {
		this.priority = priority;
	}
	
	public double getUtilization() {
		return ((double) getComputation()/getPeriod());
	}
	
	@Override
	public String toString() {
		return "Instance = [taskId: "+ this.taskID+"]";	           
	}	
}
